<%@page import="org.proddevplm.dao.data.requirements.Requirements"%>
<%@page import="java.util.List"%>
<%@page import="org.proddevplm.constants.ControllerConstants"%>
<%@page import="org.proddevplm.business.activity.constants.ActivityConstants" %>

<script>
	
	$(function(){
		$("button").button();
		$("#myReqsTable").tablesorter({
			widgets:['zebra'],
			headers:{
			3: {sorter: false}
			}
		})
	})
	
	function showAdd(){
		$("#myRequirements").hide();
		$("#inputReq").show();
	}
	
	function removeRequirement(requirement, tRow){
		var confirmReqDeletion = confirm("Do you want to remove this requirement?");
		if(confirmReqDeletion){
			var arguments = "requirement="+requirement;
			var tableRow = tRow;
			$("#"+tableRow).hide();
			
			ajaxCall("toolsManager", "8", arguments, null);
			alert('Requirement deleted successfully');
		}
	}
	
	function finishActivity(name){
		$("#activityName").val(name);
		document.forms['finishActivityForm'].submit();
	}

</script>

<%
	List<Requirements> myRequirements = (List)session.getAttribute("myRequirements");
%>

<table id="myReqsTable" class="tablesorter" style="width:100%" rules="rows" frame="hsides" bordercolor="#DBDBDB">
	<thead>
		<tr>
			<th style="width:8%; text-align:center">Crt.No</th>
			<th style="width:30%">Requirement</th>
			<th >Description</th>
			<th style="width:8%; text-align:center">Action</th>
		</tr>
	</thead>
	<tbody>
		<%for(int i=0; i<myRequirements.size(); i++){
			Requirements req = myRequirements.get(i);%>
			<tr id="row<%=i+1%>">
				<td style="text-align:center"><%=i+1 %></td>
				<td><%=req.getRequirement() %></td>
				<td><%=req.getDescription() %></td>
				<td style="text-align:center">
					<img src="/proddev/images/delete1.png" onclick="removeRequirement('<%=req.getRequirement()%>', 'row<%=i+1%>')" align="middle" width="20" height="20"/>
				</td>
			</tr>
		<%} %>
	</tbody>
</table>
<div>
	<button onclick="showAdd()" style="width:20%; font-weight:bold; float:left">Add new requirement</button>
	<button id="finishActivity" name="finishActivity" onclick="finishActivity($('#activitySelect').val())" style="width:20%; font-weight:bold; float:right">Finish activity</button>
	<div style="clear:both"></div>
</div>
<form name="finishActivityForm" method="post" action="/proddev/controller" style="margin:0">
	<input type = "hidden" name = "<%=ControllerConstants.MANAGER_KEY%>" value = "<%=ControllerConstants.ACTIVITY_MANAGER%>"/>
	<input type = "hidden" name = "<%=ControllerConstants.METHOD_KEY%>" value = "<%=ActivityConstants.CHANGE_STATUS%>"/>
	<input type="hidden" name="activityName" id="activityName">	
</form>
<div style="clear:both"></div>	